package com.example.project.controller.admin;

import com.example.project.common.Result;
import com.example.project.dto.vo.PageResult;
import com.example.project.dto.vo.admin.AdminUserVO;
import com.example.project.service.AdminUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/admin/user")
@RequiredArgsConstructor
public class AdminUserController {

    private final AdminUserService adminUserService;

    @GetMapping("/list")
    public Result<PageResult<AdminUserVO>> listUsers(@RequestParam int page, @RequestParam int size) {
        return Result.ok(adminUserService.listUsers(page, size));
    }

    @PutMapping("/state/{id}")
    public Result<String> updateState(@PathVariable Integer id, @RequestParam boolean state) {
        adminUserService.updateState(id, state);
        return Result.ok("状态已更新");
    }

    @PutMapping("/{id}")
    public Result<String> updateUser(@PathVariable Integer id, @RequestBody AdminUserVO body) {
        adminUserService.updateUser(id, body);
        return Result.ok("用户已更新");
    }

    @PutMapping("/repassword/{id}")
    public Result<String> resetPassword(@PathVariable Integer id) {
        adminUserService.resetPassword(id);
        return Result.ok("密码重置为 123");
    }
}


